#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: 李吉凯
@Email: lijk34925@hundsun.com
@Time: 2022/5/10 9:40
@File: Aml__init__.py.py
"""
import os.path

from selenium.webdriver.chrome.options import Options

from qturboframe.lib.common.web_config import web_config
from qturboframe.lib.webdriver.webdriver_factory import WebDriverFactory

from BladeFerm.Lib.Common import config, logger, DownPath, ROOT_PATH
from BladeFerm.hui_app.front_end import FrontEnd


options = Options()
# 判断是否关闭浏览器窗口运行
close_windows = config.get('Browser', 'close_brower')
close_windows_flag = True if close_windows == "True" else False
if close_windows_flag:
    options.add_argument('--headless')

# 开启debugger模式，可打开浏览器后再运行脚本。方便调试
debugger_str = config.get('Browser', 'debugger')
debugger = True if debugger_str == "True" else False
if debugger:
    driver_proxy_address = config.get('Browser', 'proxy_address')
    logger.debug('driver_proxy_address:' + driver_proxy_address)
    options.debugger_address = driver_proxy_address

# 初始化web驱动
factory = WebDriverFactory(
        browser_type="chrome",
        browser_id=web_config.driver_id)

# 设置运行参数
factory.set_chrome_options(options)
logger.debug(f'DownPath： {DownPath}')

# 设置驱动路径
driver_path = os.path.join(ROOT_PATH, 'Tools\\chromedriver\\chromedriver.exe')
factory.set_webdriver_path(driver_path)

# 获取浏览器对象
driver = factory.get_driver(download=DownPath)
# driver.implicitly_wait(60)
FE = FrontEnd(driver)
logger.info(f'打开浏览器的ID是{web_config.driver_id}')


